<?php

/**
 * login actions.
 *
 * @package    sftest
 * @subpackage login
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class loginActions extends sfActions
{
    /**
    * Executes index action
    *
    */
    public function executeIndex()
    {
        //$this->forward('default', 'module');
    }
    public function executeSubmit()
    {
    	$this->mailaddress = $this->getRequestParameter("mailaddress");
    	$this->password = $this->getRequestParameter("password");

    	if($this->mailaddress !="" && $this->password != "")
    	{
    	    $c = new Criteria;
    	    $c->add(MemberPeer::MAILADDRESS, $this->mailaddress);
    	    $c->add(MemberPeer::PASSWORD, $this->password);
    	    $member = MemberPeer::doSelectOne($c);

    	    if($member)
    	    {
    	        $this->getUser()->setAuthenticated(true);
    	        $this->getUser()->clearCredentials();
    	        $this->getUser()->addCredential("member");

    	        $this->getUser()->setAttribute("member_id", $member->getId(), sfConfig::get("sf_session_name"));
    	        $this->getUser()->setAttribute("username", $member->getUsername(), sfConfig::get("sf_session_name"));
    	        $this->redirect("/");

    	        if($member->getAdminYn() == "y")
    	        {
    	            $this->getUser()->addCredential("admin");
    	        }
    	        $this->redirect("/backend");
    	    }
    	}
    	$this->redirect("/login");
    }
    public function handleErrorSubmit()
    {
        $this->request->setParameter("mailaddress", $this->getRequestParameter("mailaddress"));
        $this->forward("login", "index");
    }

}
